export function deepClone(obj) {
	if (obj === null || typeof obj !== 'object') {
		return obj;
	}

	let clone = Array.isArray(obj) ? [] : {};

	for (let key in obj) {
		if (obj.hasOwnProperty(key)) {
			clone[key] = deepClone(obj[key]);
		}
	}
	return clone;
}

export function isEmpty(value) {
	if (value === null || value === undefined) {
		return true;
	}
	if (typeof value === 'string' && value.trim() === '') {
		return true;
	}
	if (Array.isArray(value) && value.length === 0) {
		return true;
	}
	if (typeof value === 'object' && Object.keys(value).length === 0) {
		return true;
	}
	return false;
}

export function validataTable(arr, list) {
	const NUM = arr.length
	if (!NUM) {
		uni.showModal({
			title: '无列表信息',
		});
		return true
	}
	let index = 0
	for (index; index < NUM; index++) {
		for (const item of list) {
			if (isEmpty(arr[index][item.field])) {
				uni.showModal({
					title: `表格第${Number(index) + 1}行【${item.label}】未填写，请检查`,
				});
				return true
			}
		}
	}
}

export function VhToPx(numvh) {
	let viewportHeight;
	// #ifdef H5
	viewportHeight = window.innerHeight || document.documentElement.clientHeight;
	// #endif
	// #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ
	const systemInfo = uni.getSystemInfoSync();
	viewportHeight = systemInfo.windowHeight;
	// #endif
	// #ifdef APP-PLUS
	const systemInfo = uni.getSystemInfoSync();
	viewportHeight = systemInfo.windowHeight;
	// #endif
	// 计算 15vh
	const num = viewportHeight * (numvh / 100);
	return num;
}